home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!ns.unibol.com
- From: John Girvin <jgirvin@bfs.unibol.com>
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: Collision Detects !!!!
- Date: Tue, 9 Apr 1996 14:06:01 GMT
- Message-ID: <199604091406.OAA00456@mailhost.unibol.com>
- X-NNTP-Posting-Host: ns.unibol.com
- X-Newsreader: TIN [version 1.2 PL2]
- X-Mail2News-Path: ns.unibol.com
-
- On Sun, 7 Apr 1996 11:19:56 GMT, breese@imada.ou.dk (Bjorn Reese) wrote:
- :>John Girvin (jgirvin@bfs.unibol.com) wrote:
-
- :>> if ( (px2 - bullet[i]->x) < (bullet[i]->width + player->width) &&
- :>> ^^^ ^^^^^^^^^^^^
- :>> swapped!
- :>Ok, makes sense now. I simply love it!
-
- Yeah, I thought it was pretty clever too! I didnt invent it mind, I
- just saw it somewhere and saved it for posterity.
- Glad you like it anyway :)
-
- :>On a second look it would be fatal to remove player->width from the
- :>inequality. I was initially puzzled by it's appearence, but now I've
- :>realized that it's the principal cause why the unsigned comparison works.
-
- I realised this also when I tried to further optimise my collision
- detection this way! Normal algebraic rules do not apply with unsigned
- arithmetic, something they never taught me at school :)
-
- You can make the comparison into:
-
- if ( (bullet[i]->x2 - player->x) > -(bullet[i]->width + player->width) )
- ^^ ^ ^ ^
- | \ | /
- NB! NB!
- if its easier to calculate bx2 than px2, or you want to keep px2 in a
- register (seeing as its a constant ;) and not change it with a
- sub bxreg,px2reg. Check that expression though ;)
-
- cya,
- /John.
- __________________________________________________________________________
- |/\John Girvin : developing software for Unibol Inc., speaking for myself|
- |\/jgirvin@bfs.unibol.com | Amiga,!PC,net,Trek,SF,MTB,C2H50H,house,techno|
- |girv@girvnet.demon.co.uk | Youll never take me alive, Macro$loth fiends!|
- \A1200/030-40/10M/3.0 A500/000-7/2M/2.04 464/Z80-4/0.0625M/1.0 Team AMIGA/
-